﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pixels.Interface
{
    public class Window : InterfaceElement {

        string title;
        static private int zcounter;
        public Window(string title, int x, int y, int w, int h) {
            localPosition = new Ur.Rect(x, y, w, h);
            this.title = title;
            this.zed = 10000 + (++zcounter * 10);
        }

        public override bool respondsToHilite { get { return true; } }

        public override void render() {
            if (!Visible) return;
            //var sprUp = Render.spriteInBox("modal_top", new Ur.Rect(ScreenRect.x0, ScreenRect.y0, ScreenRect.w, 47), true);
            //var sprDown = Render.spriteInBox("modal_bottom", new Ur.Rect(ScreenRect.x0, ScreenRect.y0 + ScreenRect.h - 47, ScreenRect.w, 47), true);
            //var sprLeft = Render.spriteInBox("modal_left", new Ur.Rect(ScreenRect.x0, ScreenRect.y0 + 47, 22, ScreenRect.h - 94), true);
            //var sprRight = Render.spriteInBox("modal_left", new Ur.Rect(ScreenRect.x0 + ScreenRect.w - 21, ScreenRect.y0 + 47, 21, ScreenRect.h - 94), true);
            //var spr = Render.spriteInBox("white", ScreenRect, true);            
            //spr.color = new Sargon.Color(0f, 0f, 1f);
            //spr.alpha = 0.5f; //if (IsHilit) spr.alpha = 0.9f;

            var spr = Render.spriteInBox("modal", ScreenRect, true);
            spr.zed = zed;
        }

        public override void input(Sargon.InputState state) {
            if (!Visible) return;
            if (IsHilit && state.captureKeyHeld(Sargon.Keys.Mouse1)) {
                move(state.mouseDelta);
            }
        }

        void move(Ur.crds2 delta) {
            this.localPosition = this.localPosition.move(delta.x, delta.y);
        }

        public override void tick() {
            
        }

        bool AmIOrAnyOfMyChildrenHilit {
            get {
                if (IsHilit) return true;
                foreach (var child in children) if (child.IsHilit) return true;
                return false;
            }
        }

        internal void show() {
            visible = true;
        }

        internal void hide() {
            visible = false;
        }
    }
}
